import {
  chooseAddress,
  showModal,
  showToast
} from "../../utils/asyncWx.js";
import regeneratorRuntime from "../../lib/runtime/runtime";

Page({

  /**
   * 页面的初始数据
   */
  data: {
    address: {},
    cart: [],
    totalPrice: 0,
    totalNum: 0

  },

  onShow(options) {
    const address = wx.getStorageSync('address');
    let cart = wx.getStorageSync('cart') || [];
    cart = cart.filter(v => v.checked);
    let totalPrice = 0;
    let totalNum = 0;
    cart.forEach(v => {
      if (v.checked) {
        totalPrice += v.num * v.goods_price;
        totalNum += v.num;
      }
      this.setData({
        cart,
        totalPrice,
        totalNum,
        address
      });
    })
  },

  handleOrderPay() {
    // 1判断缓存中有没有token
    const token = wx.getStorageSync("token");
    //2判断
    if (!token) {
      wx.navigateTo({
        url: '/pages/auth/auth',
      });
      return;
    }
    console.log("ycfasdg")
  },
})